#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;


struct TreeNode {
	int val;
	TreeNode* left;
	TreeNode* right;
	TreeNode() : val(0), left(nullptr), right(nullptr) {}
	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
	TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
};

class Solution {
public:
	void sumOfLeftLeaves_myself(TreeNode* root, int* x)
	{
		if (root == nullptr)
		{
			return;
		}
		if (root->left && root->left->left == nullptr && root->left->right == nullptr)
		{
			*x += root->left->val;
		}
		sumOfLeftLeaves_myself(root->left, x);
		sumOfLeftLeaves_myself(root->right, x);
	}
	int sumOfLeftLeaves(TreeNode* root) {
		int x = 0;
		sumOfLeftLeaves_myself(root, &x);
		return x;
	}
};

TreeNode* creat()
{
	TreeNode* n1 = new TreeNode(-9);
	TreeNode* n2 = new TreeNode(-3);
	TreeNode* n3 = new TreeNode(2);
	TreeNode* n4 = new TreeNode(4);
	TreeNode* n5 = new TreeNode(4);
	TreeNode* n6 = new TreeNode(0);
	TreeNode* n7 = new TreeNode(-6);
	TreeNode* n8 = new TreeNode(-5);

	n1->left = n2;
	n1->right = n3;

	n2->right = n4;
	n3->left = n5;
	n3->right = n6;
	n4->left = n7;
	n5->left = n8;
	return n1;
}
int main()
{
	Solution A;

	TreeNode* root = creat();
	int sum = A.sumOfLeftLeaves(root);
	cout << sum;
	return 0;
}